<?php

namespace IDock\Insurance\MACN\Response;

use IDock\Http\Response;
use IDock\Printer\UnderwritingRecallPrinter;

class UnderwritingRecallResponse extends AllMACNResponse
{
    public function printerInit(): Response
    {
        $underwritingRecallPrinter = new UnderwritingRecallPrinter();

        $infoList = $this->get('Info', []);

        //单条
        if (!isset($infoList[0])) {
            $status = $infoList['Status'];
            if ($status == '-1') {
                $underwritingRecallPrinter->isSuccess = false;
                $underwritingRecallPrinter->errorTip = $infoList['ErrMsg'] ?? '';
            } else {
                $underwritingRecallPrinter->isSuccess = true;
            }
        } else {
            $isSuccess = 0;
            foreach ($infoList as $item) {
                $status = $item['Status'] ?? '';

                if ($status != '0') {
                    $isSuccess -= 1;
                    $underwritingRecallPrinter->errorTip = $item['ErrMsg'] ?? '';
                } else {
                    $isSuccess += 1;
                }

                if ($isSuccess == 2) {
                    $underwritingRecallPrinter->isSuccess = true;
                } else {
                    $underwritingRecallPrinter->isSuccess = false;
                }
            }
        }

        $this->printer = $underwritingRecallPrinter;
        return $this;
    }
}